package com.itheima.aop;


import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Slf4j
//@Component
        //@Aspect
public class MyAspect01 {

    //切入点方法
    @Pointcut("execution(* com.itheima.service.*.*(..))")
    private void pt(){}


    @Before("execution(* com.itheima.service.*.*(..))")
   // @Before("pt()")
    public void before(JoinPoint joinPoint){
      //  log.info("before执行了....");
    }

    //环绕通知
    @Around("execution(* com.itheima.service.*.*(..))")
    //Around("pt()")
    public Object around(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
      //  log.info("around before执行了....");
        //调用目标对象的原始方法执行
        Object result= proceedingJoinPoint.proceed();
        //原始方法如果执行时有异常，环绕通知中的后置代码不会在执行
      //  log.info("around after执行了....");
        return result;
    }
    @After("execution(* com.itheima.service.*.*(..))")
    //After("pt()")
    public void after(JoinPoint joinPoint){
      //  log.info("after执行了....");
    }

    @AfterReturning("execution(* com.itheima.service.*.*(..))")
    //AfterReturning("pt()")
    public void afterReturning(JoinPoint joinPoint){
       // log.info("afterReturning执行了....");
    }

    @AfterThrowing("execution(* com.itheima.service.*.*(..))")
    //AfterThrowing("pt()")
    public void afterThrowing(JoinPoint joinPoint){
      //  log.info("afterThrowing执行了....");
    }




}
